/**
 * @author temsa
 * Describes the Standard Component Interface
 * @class Archetype.component.graphicalComponent
 * @name Archetype.component.graphicalComponent
 * @extends Archetype.component.abstractComponent
 */
Archetype.Component.create(
/**
 * @scope Archetype.component.graphicalComponent.prototype
 */
{
    name:"Archetype.component.graphicalComponent",
    setup: {
        dependencies:{components:{}, lib:[], css:[], html:{}}
    },
    /**
     * @function
     * Default empty constructor
     */
    initialize : _,
    /**
     * Array of parent_Elements where the component is
     */
    parent_Elements: [],
    /**
     * Generic elements for graphical uses
     */
    addUnderElement: function(parentElement) {
        try {
            var args = $A(arguments);
            args = args.without(args.first());
            this.parent_Elements.push(parentElement);
            Logger.warn(parentElement, this.parent_Elements, $H(this.render).inspect(),this.render(args));
            new Insertion.Bottom(parentElement, this.render(args));
        } catch(e) {
            Logger.error(e);
        }
    },
	/**
	 * Renders the view as a String, must be implemented by the graphical component
	 * Takes no parameters.
	 *
	 * @return {String} the view as a string to insert in the DOM
	 */
	renderViewAsString:  function() {
            if( $exist(this.templates) && $exist(this.templates.main) ) {
                return this.templates.main.evaluate(this);
            } else {
                Logger.warn("Please override 'renderViewAsString' or define a 'main' template.");
            }
            return "";
    	},
	/**
	 * Render the view. Uses renderViewAsString().
	 *
	 * @param {DOMNode} Element on which the Insertion will be applied
	 * @param {Insertion} [Insertion object] Usually prototype ones. Do not define to replace the element.
	 * @see http://www.prototypejs.org/api/insertion
	 *
	 * @exemple this.render(document.body, Insertion.Bottom);
	 */
	render: function(/*DOMNode*/element, /*Insertion*/insertionObject) {
	    if(typeof insertionObject == "undefined")
                $(element).update(this.renderViewAsString());
	    else
                new insertionObject(element, this.renderViewAsString());

            this.afterRender();
	},
	/**
	 * Called by default after a "render"<br>
	 * override this to set handlers after a typical render
	 * @function
	 */
	afterRender: _
    });
